package com.ktwlrj.core.util;

import java.io.PrintWriter;
import java.io.StringWriter;

/**
 * 异常工具
 *
 * @author zhouxuanhong
 * @date 2019-04-13 12:43
 * @since JDK1.8
 */
public class ThrowableUtil {

    /**
     * 获取堆栈信息
     *
     * @param throwable ${@link Throwable}
     * @return String ${@link String}
     */
    public static String getStackTrace(Throwable throwable) {
        StringWriter sw = new StringWriter();
        try (PrintWriter pw = new PrintWriter(sw)) {
            throwable.printStackTrace(pw);
            return sw.toString();
        }
    }
}
